Component({
    properties: {
        listData: {
            type: Array,
            default: function() {
                return [];
            }
        },
        packages: {
            type: Boolean,
            default: !1
        }
    },
    data: {
        showModalStatus: !1,
        canlendar: [],
        dataSelect: 0,
        limitDay: ""
    },
    methods: {
        _schedule: function() {
            var t = 4, a = Number(new Date().getMonth()) + 1;
            if (0 != this.data.listData.length) {
                var e = new Date(this.data.listData[0]).getMonth() + 1, n = new Date(this.data.listData[0]).getFullYear(), i = new Date(this.data.listData[this.data.listData.length - 1]).getMonth() + 1, o = new Date(this.data.listData[this.data.listData.length - 1]).getFullYear();
                (t = Number(o) > Number(n) ? (i = Number(i) + 12) - Number(e) + 1 : i - Number(e) + 1) > 3 && (t = 3), 
                a != e && (Number(o) > Number(n) ? e + 12 - a : e - a);
                var r, s = new Date(), d = Number(new Date().getMonth()) + 1, l = Number(n), h = Number(e) - 1, c = s.getDate(), D = new Date(this._formartDate(l, h + 1, c, "-")).getTime(), u = new Date(this._formartDate(l, h + 1, c, "-")).getDay(), f = [], m = [];
                r = "Number" != typeof this.data.listData[0] ? this._dateconsult(this.data.listData) : this.data.listData, 
                console.log(new Date(r[0]));
                for (var g = 0; g < t; g++) f[g] = this._total(g, l, h);
                for (var w = 0; w < t; w++) {
                    m.push({});
                    var p, _ = h + w + 1, y = l;
                    _ > 12 && (y += 1, _ -= 12), new Date(y, _ - 1, 0).getDate(), p = new Date(y, _ - 1, 1).getDay(), 
                    m[w].dataTitle = this._formartDate(y, _, "0", "ch"), m[w].month = this._monthDdd0(_), 
                    m[w].datacontent = [];
                    for (var v = 0; v < f[w]; v++) {
                        m[w].datacontent.push({});
                        var x = this._formartDate(y, _, v - p + 1, "-"), T = new Date(x).getTime(), b = this._isInArray(r, T);
                        if (0 == this.data.listData.length && (b = !0), v < p) 0 == w ? (m[w].datacontent[v].text = "", 
                        m[w].datacontent[v].link = "", m[w].datacontent[v].link = "", m[w].datacontent[v].flag = !1) : (m[w].datacontent[v].text = "", 
                        m[w].datacontent[v].link = "", m[w].datacontent[v].time = "", m[w].datacontent[v].flag = !1); else {
                            var k = T == D && m[w].month == d ? "今天" : "";
                            b ? (m[w].datacontent[v].text = k, T == D && m[w].month == d && (m[w].datacontent[v].text = "今天", 
                            this.setData({
                                limitDay: v - u
                            })), m[w].datacontent[v].link = "", m[w].datacontent[v].time = v - p + 1, m[w].datacontent[v].flag = !0, 
                            m[w].datacontent[v].appoint = "可约", T < D && 0 == r.length && (m[w].datacontent[v].flag = !1)) : T == D && m[w].month == d ? (m[w].datacontent[v].text = "今天", 
                            m[w].datacontent[v].link = "", m[w].datacontent[v].time = v - p + 1, m[w].datacontent[v].flag = !1, 
                            this.setData({
                                limitDay: v - u
                            })) : T < D ? (m[w].datacontent[v].text = "", m[w].datacontent[v].link = "", m[w].datacontent[v].time = v - p + 1, 
                            m[w].datacontent[v].flag = !1) : (m[w].datacontent[v].text = k, m[w].datacontent[v].link = "", 
                            m[w].datacontent[v].time = v - p + 1, m[w].datacontent[v].flag = !1);
                        }
                    }
                }
                var N = m[0].datacontent.findIndex(function(t, a, e) {
                    return "今天" === t.text;
                });
                if (-1 !== N) {
                    for (var M, S = [], I = new Date().getDay(), A = 0; A < I; A++) S.push({
                        flag: !1,
                        link: "",
                        text: "",
                        time: ""
                    });
                    (M = m[0].datacontent).splice.apply(M, [ 0, N ].concat(S));
                }
                this.setData({
                    canlendar: m
                });
            } else this.data.canlendar = [];
        },
        _dateconsult: function(t) {
            for (var a = [], e = 0, n = 0; n < t.length; n++) e = new Date(t[n]).getTime(), 
            a[n] = e, e = 0;
            return a;
        },
        _total: function(t, a, e) {
            return new Date(a, e + (t + 1), 0).getDate() + new Date(a, e + t, 1).getDay();
        },
        _isInArray: function(t, a) {
            if (t.indexOf && "function" == typeof t.indexOf && t.indexOf(a) >= 0) return !0;
            return !1;
        },
        _formartDate: function(t, a, e, n) {
            switch (n) {
              case "ch":
                return t + "年" + (a = a.toString()[1] ? a : "0" + a) + "月";

              default:
                return t + (n = n) + (a = a.toString()[1] ? a : "0" + a) + n + (e = e.toString()[1] ? e : "0" + e);
            }
        },
        _monthDdd0: function(t) {
            return t.toString()[1] ? t.toString() : "0" + t.toString();
        },
        _mothTap: function(t) {
            var a = t.currentTarget.dataset.idx;
            this.selectMothon != a && this.setData({
                dataSelect: a
            });
        },
        powerDrawer: function(t) {
            this.setData({
                showModalStatus: t
            });
        },
        _selectTimeTap: function(t) {
            var a = t.currentTarget.dataset.flag, e = t.currentTarget.dataset.month, n = t.currentTarget.dataset.day, i = t.currentTarget.dataset.year;
            if (a || "" == n) {
                if (a && "" != n) if (this.data.packages) if (n == this.data.selectedDay && e == this.data.selectedMonth) this.triggerEvent("getChildDate", {
                    strmonth: "",
                    strday: "",
                    strTime: ""
                }), this.setData({
                    selectedMonth: "",
                    selectedIndex: ""
                }); else {
                    var o = this._monthDdd0(n) + "日", r = this._monthDdd0(e) + "月", s = i.split("年").join("-");
                    s = s.split("月").join("-") + n, this.triggerEvent("getChildDate", {
                        strmonth: r,
                        strday: o,
                        strTime: s
                    });
                    var d = e, l = n;
                    this.setData({
                        selectedMonth: d,
                        selectedDay: l
                    });
                } else this._promt(a, e, n);
            } else this._promt(a, e, n);
        },
        _promt: function(t, a, e) {
            if (t || "" == e) {
                if (t && "" != e) {
                    var n = a + "月" + this._monthDdd0(e) + "日可以预约体检，请去选择体检套餐";
                    wx.showToast({
                        title: n,
                        icon: "none",
                        duration: 2e3,
                        mask: !0
                    });
                }
            } else wx.showToast({
                title: "当天不可预约，请选择其他时间",
                icon: "none",
                duration: 2e3,
                mask: !0
            });
        }
    },
    lifetimes: {
        attached: function() {
            this._schedule();
        }
    }
});